{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/media/tlw/move/opt/jdk-11.0.11/lib/server/libjvm.so\n"
     ]
    },
    {
     "ename": "OSError",
     "evalue": "JVM cannot be restarted",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mOSError\u001b[0m                                   Traceback (most recent call last)",
      "Cell \u001b[0;32mIn [2], line 9\u001b[0m\n\u001b[1;32m      7\u001b[0m jvmPath \u001b[39m=\u001b[39m jpype\u001b[39m.\u001b[39mgetDefaultJVMPath() \n\u001b[1;32m      8\u001b[0m \u001b[39mprint\u001b[39m(jvmPath)\n\u001b[0;32m----> 9\u001b[0m jpype\u001b[39m.\u001b[39;49mstartJVM(jvmPath) \n\u001b[1;32m     10\u001b[0m jpype\u001b[39m.\u001b[39mjava\u001b[39m.\u001b[39mlang\u001b[39m.\u001b[39mSystem\u001b[39m.\u001b[39mout\u001b[39m.\u001b[39mprintln(\u001b[39m\"\u001b[39m\u001b[39mhello world!\u001b[39m\u001b[39m\"\u001b[39m) \n\u001b[1;32m     11\u001b[0m jpype\u001b[39m.\u001b[39mshutdownJVM()\n",
      "File \u001b[0;32m/media/tlw/move/py310/lib/python3.10/site-packages/jpype/_core.py:169\u001b[0m, in \u001b[0;36mstartJVM\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m    167\u001b[0m \u001b[39mglobal\u001b[39;00m _JVM_started\n\u001b[1;32m    168\u001b[0m \u001b[39mif\u001b[39;00m _JVM_started:\n\u001b[0;32m--> 169\u001b[0m     \u001b[39mraise\u001b[39;00m \u001b[39mOSError\u001b[39;00m(\u001b[39m'\u001b[39m\u001b[39mJVM cannot be restarted\u001b[39m\u001b[39m'\u001b[39m)\n\u001b[1;32m    171\u001b[0m args \u001b[39m=\u001b[39m \u001b[39mlist\u001b[39m(args)\n\u001b[1;32m    173\u001b[0m \u001b[39m# JVM path\u001b[39;00m\n",
      "\u001b[0;31mOSError\u001b[0m: JVM cannot be restarted"
     ]
    }
   ],
   "source": [
    "# python 调用Oracle的JDBC\n",
    "# 原文: https://www.cnblogs.com/yoyowin/p/12130937.html\n",
    "\n",
    "# 1. 调用JVM \n",
    "# pip install jpype1\n",
    "\n",
    "import jpype \n",
    "jvmPath = jpype.getDefaultJVMPath() \n",
    "print(jvmPath)\n",
    "jpype.startJVM(jvmPath) \n",
    "jpype.java.lang.System.out.println(\"hello world!\") \n",
    "jpype.shutdownJVM()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 2. 调用Oracle的JDBC\n",
    "# 原文: https://blog.csdn.net/xiuxiuxiu666/article/details/109469229\n",
    "\n",
    "import jaydebeapi\n",
    "url = 'jdbc:oracle:thin:@31.0.***.***:1521:orcl'\n",
    "user = '****'\n",
    "password = '****'\n",
    "dirver = 'oracle.jdbc.OracleDriver'\n",
    "jarFile = 'ojdbc6-11.2.0.3.jar'\n",
    "with jaydebeapi.connect(dirver,url,[user,password],jarFile) as conn:\n",
    "    # 判断连接是否成功\n",
    "    if conn:\n",
    "        print('ok')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.10.6 ('py310')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.6"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "49ec5068d4d6d3736c39d3918a16f1ca551a23384109b69898c01c2015d1370c"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
